using ControlCenter.Model;
using ControlCenter.Model.BizEntities;
using ControlCenter.Operation;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using ControlCenter.Model.WebApiDto;

namespace ControlCenter.ApplicationService
{
    /// <summary>
    /// 包管理
    /// </summary>
    public interface IPackageManagementService
    {
        #region  -- 包文件操作 -------------------------------------------------------------------------------------------------------
        /// <summary>
        ///查询指定的包信息
        /// </summary>
        /// <param name="packageId"></param>
        /// <returns></returns>
        Task<(byte[] fileStream, ProjectPackageInfo packageInfoDto)> ReadPackageFile(Guid packageId);

        /// <summary>
        /// 保存包到本地
        /// </summary>
        /// <param name="packageInfoDto"></param>
        /// <param name="package"></param>
        /// <returns></returns>
        Task<bool> SavePackages(PackageInfoDto packageInfoDto, IFormFile package);
        #endregion
        

        #region -- 机器人的包管理 -------------------------------------------------------------------------------------------------------
        /// <summary>
        /// 获取所有机器人的应用摘要信息列表
        /// </summary>
        /// <returns></returns>
        Task<IEnumerable<RobotPackageShortInfo>> QueryRobotPackageShortInfo();
        /// <summary>
        /// 查询机器人的所有任务包
        /// </summary>
        /// <returns></returns>
        Task<IEnumerable<RobotPackageInfo>> QueryRobotPackageInfo(Guid robotId);
        /// <summary>
        /// 查询机器人待执行的任务包
        /// </summary>
        /// <param name="robotId"></param>
        /// <returns></returns>
        Task<IEnumerable<WaitExecutionPackageDto>> QueryRobotWaitExectionPackage(Guid robotId);
        /// <summary>
        /// 读取机器人的包信息列表，供编辑机器人包使用
        /// </summary>
        /// <param name="robotId"></param>
        /// <returns></returns>
        Task<IEnumerable<SaveRobotPackageInfo>> QuerySaveRobotPackageInfo(Guid robotId);
        /// <summary>
        /// 保存机器人的包及设定数据
        /// </summary>
        /// <param name="saveDto"></param>
        /// <returns></returns>
        Task<bool> UpdateRobotPackageInfo(SaveRobotInfoDto saveDto);
        /// <summary>
        /// 更新机器人的包状态（启用/停用）
        /// </summary>
        /// <param name="rpId"></param>
        /// <param name="packageStatus"></param>
        /// <returns></returns>
        Task UpdateRobotPackagePackageStatus(Guid rpId, int packageStatus);
        /// <summary>
        /// 删除机器人的包
        /// </summary>
        /// <param name="rpId"></param>
        /// <returns></returns>
        Task DeleteRobotPackage(Guid rpId);
        #endregion
        

        #region -- 包管理 -------------------------------------------------------------------------------------------------------
        /// <summary>
        /// 查询包，返回包信息列表
        /// </summary>
        /// <param name="paramDto"></param>
        /// <returns></returns>
        Task<PagedData<ProjectPackageInfo>> QueryPackageInfo(PackageQueryDto paramDto);
        /// <summary>
        /// 获取单个包信息
        /// </summary>
        /// <param name="packageId"></param>
        /// <returns></returns>
        Task<ProjectPackageInfo> FindPackageInfo(Guid packageId);
        /// <summary>
        /// 更新包信息（不存在时新增）
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        Task<Tuple<bool, string>> SavePackageInfo(ProjectPackageInfo param);
        /// <summary>
        /// 删除包，已被机器人使用的包不允许删除
        /// </summary>
        /// <param name="packageId"></param>
        /// <returns></returns>
        Task<Tuple<bool, string>> DeletePackageInfo(Guid packageId);
        #endregion

        ///// <summary>
        ///// 更新包状态
        ///// </summary>
        ///// <param name="updatePackageStatusDto"></param>
        ///// <returns></returns>
        //Task<bool> UpdatePackageStatus(UpdatePackageStatusDto updatePackageStatusDto);

        #region -- 包参数配置 -------------------------------------------------------------------------------------------------------
        /// <summary>
        /// 查询指定应用包的参数配置
        /// </summary>
        /// <param name="packageId">应用包ID</param>
        /// <returns></returns>
        Task<List<PackageConfigItem>> QueryPackageConfig(Guid packageId);

        /// <summary>
        /// 更新应用包的参数配置
        /// </summary>
        /// <param name="packageConfigItems"></param>
        /// <returns></returns>
        Task<Tuple<bool, string>> UpdatePackageConfig(List<PackageConfigItem> packageConfigItems);
        #endregion
    }
}
